#pragma once

#include <windows.h>
#include <iostream>

#include "DataTypes.h"
#include "XString.h"


namespace std {
	inline ostream & operator<<(ostream &os, const ::SYSTEMTIME& t) {
		os << "SYSTEMTIME";
		return os;
	};
}

namespace events {

typedef unsigned int uint32;


/**
 * This class handles standard header of ABPA files.
 * The format of the file is:
 * () 4 bytes of "ABPA" string
 * () 4 bytes of version number
 * () SYSTEMTIME - when was the monitoring started for current process
 * () XString - name of the process (stored in standard XString format: length + data)
 */
class AbpaFileFormat {
public:
	typedef unsigned int uint32;

public:
	/** initializes structure with current process's info */
	AbpaFileFormat(DWORD startTime = 0);

	/** loads configuration from file */
	AbpaFileFormat(std::istream &is);


public:
	/** saves file header */
	void saveAbpaHeader(std::ostream &os) const;

	/** @return whether the file is in correct format */
	inline bool isValid(void) const { return _valid; }

	/** @return version of ABPA file */
	inline uint32 getVersion(void) const { return _version; }
	
	/** @return time when the file was created */
	inline const SYSTEMTIME & getTime(void) const { return _stime(); }

	/** @return time in msec from the moment the system was started, can be used as relative time */
	inline DWORD getTickCount(void) const { return _tcount(); }

	/** @return the name of the process */
	inline const platform::XString & getProcessName(void) const { return _pname; }
	

private:
	static const char * MAGIC_FILE_HEADER;
	static const uint32 CURRENT_VERSION;

	bool _valid;
	uint32 _version;
	GenericDataType<::SYSTEMTIME> _stime;
	GenericDataType<DWORD> _tcount;
	platform::XString _pname;	
};


}  // end namespace
